unit uniGroundSea;

interface

uses
  uniGround,
  gl,
  Classes;

type
  { GroundSea }

  GroundSea = class(Ground)
  public
    size: Single;

    constructor Create;
    destructor Destroy; override;

    procedure drawGL;override;
    procedure setVariation(index: Integer);override;
  end;


var
  vert: array[0..3, 0..2] of Single =
  (
    (20.5, 15.5, 0.0),
    (-20.5, 15.5, 0.0),
    (20.5, -15.5, 0.0),
    (-20.5, -15.5, 0.0)
    );


implementation

uses
  uniGroundSeaSegment,
  uniGlobal,
  PNGLoader;


{ GroundSea }

constructor GroundSea.Create;
var
  s: array[0..1] of Single;
  seg, tmp: GroundSegment;
begin
  inherited Create;
  pos[0] := 0.0;
  pos[1] := 0.0;
  pos[2] := 0.0;

  LoadTexture('png/gndBaseSea.png', tex[Integer(Base)]);

  size := 21.0;
  s[0] := size;
  s[1] := size;
  rootSeg := GroundSeaSegment.Create(pos, s, Self);

  pos[1] := size * 2.0;
  seg := GroundSeaSegment.Create(pos, s, Self);
  rootSeg.next := seg;

  pos[1] := 0.0;
  tmp := GroundSeaSegment.Create(pos, s, Self);
  seg.next := tmp;
  tmp.back := seg;
end;

destructor GroundSea.Destroy;
begin
  rootSeg.Destroy;
  inherited;
end;

procedure GroundSea.drawGL;
var
  seg, tmp: GroundSegment;
  s2 : Single;
  p: array[0..2] of Single;
  s: array[0..1] of Single;
begin
  glClearColor(0.15, 0.12, 0.10, 1.0);

  s2 := size * 2.0;

  seg := rootSeg.next;
  while Boolean(seg) do
  begin
    seg.drawGL;

    seg.pos[1] := seg.pos[1] + uniGlobal.scrollSpeed;
    if seg.pos[1] < -s2 then
    begin
      seg.back.next := nil;
      seg.Destroy;
      p[0] := 0.0;
      p[1] := size * 2.0;
      p[2] := 0.0;
      s[0] := size;
      s[1] := size;
      tmp := GroundSeaSegment.Create(p, s, Self);
      rootSeg.next.back := tmp;
      tmp.next := rootSeg.next;
      tmp.back := rootSeg;
      rootSeg.next := tmp;
      Break;
    end;
    seg := seg.next;
  end;
end;

procedure GroundSea.setVariation(index: Integer);
begin
  variation := 0;
end;

end.

